# 任务一：设计超市购物系统
# 购物系统业务需求V1.0：
# 购物：
#     1.用户的账户里有钱
#     2.用户可推一个空的购物车进商场
#     3.开始购物，将自己想要的商品添加购物车
#     4.打印购物小条
# 输入指定商品列表

goods = [["篮球", 68], ["足球", 148], ["排球", 24], ["台球", 30]]
print("商品编号", "商品名称", "商品价格")
for i in range(4):
    print(i + 1, end="\t")
    print(goods[i][0], end="\t\t")
    print(goods[i][1])
shopping_cart = []
shopping_cart1 = []
shopping_cart2 = []
shopping_cart3 = []
n = []
user_money = 5000
sum_money = 0
user_question = input("是否开始购物？y/n?:")
while user_question == "y":

    if user_money > 0 and user_question == "y":
        user_question = input("是否继续购物？y/n?:")
        if user_question == "y":
            user_answer = input("请输入您想要购买的商品编号：")
            if user_answer.isdigit():
                user_answer = int(user_answer)
                if user_answer == 1 or user_answer == 2 or user_answer == 3 or user_answer == 4:
                    if user_money > sum_money:
                        shopping_cart.append(goods[user_answer - 1][0])
                        shopping_cart2.append(goods[user_answer - 1][1])
                        sum_money = sum_money + goods[user_answer - 1][1]
                        user_money = user_money - sum_money
                    else:
                        n.append(1)
                        print("您的余额不足，请联系工作人员进行充值！")
            else:
                print("您的输入有误！")
        else:
            for cart in shopping_cart:
                if cart not in shopping_cart1:
                    shopping_cart1.append(cart)
                    n.append(1)
                else:
                    n[shopping_cart1.index(cart)] += 1
                    num += 1
            for cart2 in shopping_cart2:
                if cart2 not in shopping_cart3:
                    shopping_cart3.append(cart2)
else:
    print("商品列表：", shopping_cart1)
    print("商品单价", shopping_cart3)
    print("商品数量:", n)
    print("商品总金额：", sum_money)
    print("账户余额：", user_money)
    print("欢迎下次光临！")

# 购物系统业务需求V2.0：
#     现在用户在进商场之前需要从10张优惠券中，随机抽取一张优惠券。
#     比如抽到一个空凋的8折优惠券，后面在购物的过程中，空凋就可以按照8折后的价格来购买。

import random
goods = [["篮球", 68], ["足球", 148], ["排球", 24], ["台球", 30]]
print("商品编号", "商品名称", "商品价格")
for i in range(4):
    print(i + 1, end="\t")
    print(goods[i][0], end="\t\t")
    print(goods[i][1])
shopping_cart = []
shopping_cart1 = []
shopping_cart2 = []
shopping_cart3 = []
n = []
user_money = 5000
sum_money = 0
yh_money = 0
user_off = random.randint(1, 10)
user_question = input("是否开始购物？y/n?:")
while user_question == "y":

    if user_money > 0 and user_question == "y":
        user_question = input("是否继续购物？y/n?:")
        if user_question == "y":
            user_answer = input("请输入您想要购买的商品编号：")
            if user_answer.isdigit():
                user_answer = int(user_answer)
                if user_answer == 1 or user_answer == 2 or user_answer == 3 or user_answer == 4:
                    if user_money > sum_money:
                        shopping_cart.append(goods[user_answer - 1][0])
                        shopping_cart2.append(goods[user_answer - 1][1])
                        sum_money = sum_money + goods[user_answer - 1][1] * user_off / 10
                        yh_money = goods[user_answer - 1][1] - goods[user_answer - 1][1] * user_off / 10
                        user_money = user_money - sum_money
                    else:
                        n.append(1)
                        print("您的余额不足，请联系工作人员进行充值！")
            else:
                print("您的输入有误！")
        else:
            for cart in shopping_cart:
                if cart not in shopping_cart1:
                    shopping_cart1.append(cart)
                    n.append(1)
                else:
                    n[shopping_cart1.index(cart)] += 1
            for cart2 in shopping_cart2:
                if cart2 not in shopping_cart3:
                    shopping_cart3.append(cart2)
else:
    print("商品列表：", shopping_cart1)
    print("商品单价", shopping_cart3)
    print("商品数量:", n)
    print("折扣为：", user_off, "折")
    print("优惠金额：", yh_money)
    print("商品总金额：", sum_money)
    print("账户余额：", user_money)
    print("欢迎下次光临！")
# 任务二：输入一个字符串，输出最后一个单词的长度

s = input("请输入：")
s = s.split(' ')
s = len(s[-1])
print(s)

# 任务三：有1、2、3、4个数字，能组成多少个互不相同且无重复数字的三位数？都是多少？

a = 100
b = 10
c = 1
count = 0
num = 0
nums = []
for a in range(1, 5):
    for b in range(1, 5):
        for c in range(1, 5):
            # print(a, b, c)
            if a != b and b != c and c != a:
                num = a * 100 + b * 10 + c
                count = count + 1
                nums.append(num)

# print("能组成", count, "个互不相同且无重复数字的三位数", "\n", "分别为:", nums)

# 任务四：一个整数，它加上100后是一个完全平方数，再加上168又是一个完全平方数，请问该数是多少？

import math

for i in range(-100, 27956):
    if 168 % i == 0:
        j = 168 / i
        if i > j and (i + j) % 2 == 0 and (i - j) % 2 == 0:
            n = int((i - j) / 2)
            x = int(n ** 2 - 100)
            y = int(math.sqrt(x + 100))
            z = int(math.sqrt(x + 268))
            print(x, y, z)

# 任务五：打印出所有的“水仙花数” ，所谓“水仙花数”是指一个三位数，其各位数字立方和等于该数本身。

for i in range(100, 1000):
    a = i // 100
    print(a)
    b = i // 10 % 10
    c = i % 10
    if a ** 3 + b ** 3 + c ** 3 == i:
        print(i)

# 例如： 153是一个“水仙花数” ，因为153=1的三次方＋5的三次方＋3的三次方。

任务六：输入两个整数，求最大公因数
num1 = int(input("请输入一个数："))
num2 = int(input("请再输入一个数："))
a = 0
if num1 > num2:
    m = num2
else:
    m = num1
for i in range(1, m + 1):
    if num1 % i == 0 and num2 % i == 0:
        a = i
print(num1, "与", num2, '的最大公约数为：%d' % a)
